package com.kdg.thread;

/**
 * @author kong
 */
public class VolitileTest {

    public static class RunAddIThread extends Thread {
        public volatile boolean stop = false;

        @Override
        public void run() {
            int i = 0;
            while (!stop) {
                i++;
            }
            System.out.println("RunAddIThread is finished...");
        }

        public void setStop(boolean stop) {
            this.stop = stop;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        RunAddIThread runAddIThread = new RunAddIThread();
        runAddIThread.start();
        Thread.sleep(2000);
        runAddIThread.setStop(true);
        System.out.println("HasFinished...");
    }
}
